package com.aco.party.web.validator.system;

import com.aco.party.web.command.system.EditProfileCommand;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class EditPasswordValidator implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return EditProfileCommand.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
//		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "oldInputPwd", "oldInputPwd.empty","原密码输入不能为空！");
//		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPwd", "newPwd.empty","新密码输入不能为空！");
//		EditProfileCommand command = (EditProfileCommand) target;
//		if(!StringUtils.isEmpty(command.getOldPwd())&&!command.getOldPwd().equals(new Sha256Hash(command.getOldInputPwd()).toHex())){
//			errors.rejectValue("oldInputPwd", "oldInputPwd.notSame", "输入原密码不正确！");
//		}
//		if(!StringUtils.isEmpty(command.getNewPwd())&&new Sha256Hash(command.getNewPwd()).toHex().equals(command.getOldPwd())){
//			errors.rejectValue("newPwd", "newPwd.same", "输入新密码不能和原密码相同！");
//		}
	}

}
